/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.dto.MessageDto;
/*     */ import com.wgcloud.entity.DbInfo;
/*     */ import com.wgcloud.service.DbInfoService;
/*     */ import com.wgcloud.service.DbTableService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import com.wgcloud.util.jdbc.ConnectionUtil;
/*     */ import com.wgcloud.util.license.LicenseUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.jdbc.core.JdbcTemplate;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/dbInfo"})
/*     */ public class DbInfoController
/*     */ {
/*  42 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.DbInfoController.class);
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DbInfoService dbInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DbTableService dbTableService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private ConnectionUtil connectionUtil;
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"validate"})
/*     */   public String valdateDbInfo(DbInfo dbInfo, Model model, HttpServletRequest request) {
/*  64 */     MessageDto messageDto = new MessageDto();
/*     */     try {
/*  66 */       JdbcTemplate JdbcTemplate = this.connectionUtil.getJdbcTemplate(dbInfo);
/*  67 */       if (JdbcTemplate == null) {
/*  68 */         messageDto.setCode("1");
/*  69 */         messageDto.setMsg("连接数据库错误，请检查参数是否正确。请在系统信息里查看日志");
/*     */       } else {
/*  71 */         messageDto.setCode("0");
/*  72 */         messageDto.setMsg("连接数据库成功");
/*     */       } 
/*  74 */     } catch (Exception e) {
/*  75 */       logger.error("测试数据源信息错误", e);
/*  76 */       this.logInfoService.save("测试数据源信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/*  79 */     return JSONUtil.toJsonStr(messageDto);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String DbInfoList(DbInfo dbInfo, Model model, HttpServletRequest request) {
/*  92 */     Map<String, Object> params = new HashMap<>();
/*     */     
/*     */     try {
/*  95 */       LicenseUtil.maxLicense_10(model, request);
/*     */ 
/*     */       
/*  98 */       PageInfo pageInfo = this.dbInfoService.selectByParams(params, dbInfo.getPage().intValue(), dbInfo.getPageSize().intValue());
/*  99 */       PageUtil.initPageNumber(pageInfo, model);
/* 100 */       model.addAttribute("pageUrl", "/dbInfo/list?1=1");
/* 101 */       model.addAttribute("page", pageInfo);
/* 102 */     } catch (Exception e) {
/* 103 */       logger.error("查询数据源信息错误", e);
/* 104 */       this.logInfoService.save("查询数据源信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 107 */     return "mysql/dbList";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String edit(Model model, HttpServletRequest request) {
/* 120 */     String errorMsg = "添加数据源错误";
/* 121 */     String id = request.getParameter("id");
/* 122 */     DbInfo dbInfo = new DbInfo();
/*     */     
/*     */     try {
/* 125 */       Map<String, Object> params = new HashMap<>();
/* 126 */       int dbSize = this.dbInfoService.countByParams(params);
/* 127 */       if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 128 */         return "redirect:/dbInfo/list?liceFlage=1";
/*     */       }
/*     */ 
/*     */       
/* 132 */       if (StringUtils.isEmpty(id)) {
/* 133 */         model.addAttribute("dbInfo", dbInfo);
/* 134 */         return "mysql/addDb";
/*     */       } 
/* 136 */       dbInfo = this.dbInfoService.selectById(id);
/* 137 */       model.addAttribute("dbInfo", dbInfo);
/* 138 */     } catch (Exception e) {
/* 139 */       logger.error(errorMsg, e);
/* 140 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 142 */     return "mysql/addDb";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveDbInfo(DbInfo dbInfo, Model model, HttpServletRequest request) {
/*     */     try {
/* 157 */       if (StringUtils.isEmpty(dbInfo.getId())) {
/* 158 */         this.dbInfoService.save(dbInfo);
/*     */       } else {
/* 160 */         this.dbInfoService.updateById(dbInfo);
/*     */       } 
/* 162 */     } catch (Exception e) {
/* 163 */       logger.error("保存数据源错误", e);
/* 164 */       this.logInfoService.save("保存数据源错误", e.toString(), "1");
/*     */     } 
/* 166 */     return "redirect:/dbInfo/list?msg=save";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 181 */     String errorMsg = "删除数据源信息错误";
/* 182 */     DbInfo DbInfo = new DbInfo();
/*     */     try {
/* 184 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 185 */         String[] ids = request.getParameter("id").split(",");
/* 186 */         for (String id : ids) {
/* 187 */           DbInfo = this.dbInfoService.selectById(id);
/* 188 */           this.logInfoService.save("删除数据源：" + DbInfo.getAliasName(), "数据库别名：" + DbInfo.getAliasName(), "0");
/* 189 */           this.dbTableService.deleteByDbInfoId(DbInfo.getId());
/*     */         } 
/* 191 */         this.dbInfoService.deleteById(ids);
/*     */       } 
/* 193 */     } catch (Exception e) {
/* 194 */       logger.error(errorMsg, e);
/* 195 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 197 */     return "redirect:/dbInfo/list?msg=del";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/DbInfoController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */